﻿using BP.DA;
using BP.En;
using BP.Sys;
using BP.Web;
using System.Data;

namespace BP.WF.DTS
{
    /// <summary>
    /// Method 的摘要说明
    /// </summary>
    public class GenerBlankTables : Method
    {
        /// <summary>
        /// 不带有参数的方法
        /// </summary>
        public GenerBlankTables()
        {
            this.Title = "生成数据为空的tabls";
            this.Help = "生成数据为空的tabls";
            this.Warning = "此功能要在测试环境里执行，确认是测试环境吗？";
            this.Icon = "";
            this.GroupName = "系统维护";
        }
        /// <summary>
        /// 设置执行变量
        /// </summary>
        /// <returns></returns>
        public override void Init()
        {
            //this.Warning = "您确定要执行吗？";
            //HisAttrs.AddTBString("P1", null, "原密码", true, false, 0, 10, 10);
            //HisAttrs.AddTBString("P2", null, "新密码", true, false, 0, 10, 10);
            //HisAttrs.AddTBString("P3", null, "确认", true, false, 0, 10, 10);
        }
        /// <summary>
        /// 当前的操纵员是否可以执行这个方法
        /// </summary>
        public override bool IsCanDo
        {
            get
            {
                if (WebUser.No.Equals("admin") == true)
                    return true;
                return false;
            }
        }
        /// <summary>
        /// 执行
        /// </summary>
        /// <returns>返回执行结果</returns>
        public override object Do()
        {
            if (BP.Web.WebUser.No != "admin")
                return "非法的用户执行。";

            SFDBSrc src = new SFDBSrc("local");
            DataTable dt= src.GetTables();

            string strs = "";
            foreach (DataRow dr in dt.Rows)
            {
                string table = dr[0].ToString();
                string sql = "SELECT COUNT(*) as nUM FROM "+table+" ";
                int num=DBAccess.RunSQLReturnValInt(sql);
                if (num == 0)
                    strs = " DROP TABLE " + table+" ;";
            }
            return "执行成功："+strs;
        }
    }
}
